﻿@{
    ViewData["Title"] = "广告内容管理";
    Layout = "~/Areas/Manager/Views/Shared/_Layout.cshtml";
}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-header">广告内容</div>
                <div class="layui-card-body">
                    <div class="layui-form">
                        <div class="layui-row">
                            <div class="layui-form-item">
                                <div class="layui-col-md3" style="padding-left:0">
                                    <div class="input-group">
                                        <input type="text" id="keyWords" name="keyWords" placeholder="请输入广告位置名称" autocomplete="off" class="layui-input">
                                        <span class="input-group-btn">
                                            <button class="layui-btn" id="search">
                                                <i class="layui-icon layui-icon-search"></i>
                                            </button>
                                        </span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="layui-row">
                        <div class="layui-btn-container">
                            <div class="layui-btn-group">
                                <button id="return" class="layui-btn layui-btn-sm" onclick="window.location.href='AdpositionIndex'"><i class="layui-icon">&#xe65c;</i>返回</button>
                                <button id="add" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe654;</i>增加</button>
                                <input type="hidden" id="AdvPositionId" value="@ViewBag.AdvPositionId" />
                                <button id="deleteAll" class="layui-btn layui-btn-sm layui-btn-danger"><i class="layui-icon">&#xe640;</i>删除</button>
                            </div>
                        </div>
                    </div>
                    <div class="layui-row">
                        <table class="layui-table" lay-data="{ page:true, id:'list'}" lay-filter="list">
                            <thead>
                                <tr>
                                    <th lay-data="{checkbox:true, fixed: true}"></th>
                                    <th lay-data="{field:'advertisementId',width:120}">广告ID</th>
                                    <th lay-data="{field:'advertisementName'}">广告名称</th>
                                    <th lay-data="{field:'sort',edit:'sequence',sort: true,width:140}">显示顺序</th>
                                    <th lay-data="{field:'contentType',templet: '#contentType',width:140}">显示类型</th>
                                    <th lay-data="{field:'status',templet: '#status',width:140}">广告状态</th>
                                    <th lay-data="{toolbar:'#tableoption',width:100}">操作</th>
                                </tr>
                            </thead>
                        </table>
                        <script type="text/html" id="contentType">
                            {{#  if(d.contentType==0){ }}
                            <span>文字</span>
                            {{#  } else if(d.contentType==1){ }}
                            <span>图片</span>
                            {{#  } else if(d.contentType==2){ }}
                            <span>flash</span>
                            {{#  } else if(d.contentType==3){ }}
                            <span>代码</span>
                            {{#  } }}
                        </script>
                        <script type="text/html" id="status">
                            {{#  if(d.status==1){ }}
                            <span class="layui-badge layui-bg-green">有效</span>
                            {{#  } else if(d.status==0){ }}
                            <span class="layui-badge layui-bg-orange">无效</span>
                            {{#  } else if(d.status==-1){ }}
                            <span>欠费停止</span>
                            {{#  } }}
                        </script>
                        <script type="text/html" id="tableoption">
                            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                        </script>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

@section scriptsfeet
    {
    <script type="text/javascript">
        layui.config({
            base: '/layuiadmin/' //自定义模块路径
        }).use(['sykjwh','table'], function () {
            var $ = layui.$, sykjwh = layui.sykjwh, table = layui.table;
            //绑定数据
            sykjwh.dataBind('@Url.Action("AdvertisementList", "Ad", new { area = Constant.AREAMANAGER })', {
                advPositionId: $.trim($("#AdvPositionId").val())
            });

    
            //批量删除
            $("#deleteAll").click(function () {
                sykjwh.batOperate('@Url.Action("AdvertisementDeleteAll", "Ad", new { area = Constant.AREAMANAGER })', 'advertisementId');
            });

             //添加
            $("#add").click(function () {
                sykjwh.openFull('添加广告内容', '@Url.Action("AdvertisementAdd", "Ad", new {area = Constant.AREAMANAGER})/' + $("#AdvPositionId").val());
            });

            //编辑
            table.on('tool(list)', function (obj) {
                var data = obj.data;//获得当前行数据
                sykjwh.openFull('编辑广告内容', '@Url.Action("AdvertisementEdit", "Ad", new { area = Constant.AREAMANAGER })/' + data.advertisementId);
            });

             //在表格中编辑sort
            table.on('edit(list)', function (obj) {
                var value = obj.value, //得到修改后的值
                data = obj.data, //得到所在行所有键值
                field = obj.field; //得到字段
                sykjwh.request("@Url.Action("AdvertisementSortEdit", "Ad", new { area = Constant.AREAMANAGER })?advertisementId=" + data.advertisementId +"&sort=" +value +"&field=" +field,"POST");
            });

            //搜索
            $("#search").click(function () {
                //绑定数据
                sykjwh.dataBind('@Url.Action("AdvertisementList", "Ad", new { area = Constant.AREAMANAGER })', {
                    keyWords: $.trim($("#keyWords").val())
                });
            });
        });
    </script>
}
